How can I convert a date (yyyy,mm,dd) to a Julian Date and write it to a csv file? Here's the script I'm trying to write:
import csv from jdcal import gcal2jd, jd2gcal
with open('/home/pi/Data/datesidc.csv') as csvfile: readCSV = csv.reader(csvfile, delimiter=',') for row in readCSV: gcal2jd(row[0],row[1],row[2]) # print(row[0],row[1],row[2],)
You must be logged in to post. Please login or register an account.
Apparently datetime can convert to Julian. Never heard of it before now. https://pypi.python.org/pypi/DateTime/2.12.7 (search for julian).
I would HIGHLY recommend you stop using CSV reader at this point, use Pandas. From there, apply datetime's JulianDay to the date column.
Not sure how you're going to do that with using commas as the the delimiter and in the date, but maybe you have some data still in sqlite that is properly delimited.
-Harrison 9 years ago
You must be logged in to post. Please login or register an account.
Here is my revised step, which brings me a couple of steps closer: (Script used, jdcal https://pypi.python.org/pypi/jdcal.] Here's the script:
from jdcal import gcal2jd, jd2gcal import pandas as pd
# sidc2015.csv has one record for each day of the year df = pd.read_csv('/home/pi/Data/sidc2015.csv')
# df.set_index('Yr',inplace=T) # print(df.head())
# loop through sidc2015.csc. # Create csv file that has Julian Date as first field: # Yr,Mo,Day,dt,spots,c,d,e # JulianDate,Yr,Mo,Day,dt,spots,c,d,e # And write it out to, "new.csv) for row in df: jd = gcal2jd(2016,1,1) JD =(jd[0]+ jd[1]) print(JD)
# Write new file df.to_csv("/home/pi/Data/new.csv")
-davidjackson1955 9 years ago
You must be logged in to post. Please login or register an account.